package com.zmn.plat.common.dictionary;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 渠道工单类型枚举
 *
 * @author linfeng
 * @since 2020/10/30 15:44
 */
public enum ChannelWorkOrderTypeEnum {

    /**
     * values
     */
    YYHT(1, "运营后台"),
    GCSAPP(2, "工程师APP"),
    FWSMH(3, "服务商门户"),
    THIRDAPI(4, "第三方API"),
    NOTALLOWED(5, "均不允许")
    ;

    /**
     * 运营后台
     */
    public static final int CONSTS_YYHT = 1;
    /**
     * 工程师APP
     */
    public static final int CONSTS_GCSAPP = 2;
    /**
     * 服务商门户
     */
    public static final int CONSTS_FWSMH = 3;
    /**
     * 第三方API
     */
    public static final int CONSTS_THIRDAPI = 4;
    /**
     * 均不允许
     */
    public static final int CONSTS_NOTALLOWED = 5;

    private Integer code;
    private String name;

    ChannelWorkOrderTypeEnum(Integer code, String name) {
        this.code = code;
        this.name = name;
    }

    public Integer getCode() {
        return code;
    }

    public String getName() {
        return name;
    }

    public static ChannelWorkOrderTypeEnum of(Integer code) {
        if(code == null){
            return null;
        }
        switch (code) {
            case 1:
                return YYHT;
            case 2:
                return GCSAPP;
            case 3:
                return FWSMH;
            case 4:
                return THIRDAPI;
            case 5:
                return NOTALLOWED;
            default:
                return null;
        }
    }

    public static String getName(Integer code) {
        ChannelWorkOrderTypeEnum of = of(code);
        return of == null ? null : of.getName();
    }

    public static ChannelWorkOrderTypeEnum[] completeOrCancelType() {
        return new ChannelWorkOrderTypeEnum[]{YYHT, GCSAPP, FWSMH, THIRDAPI};
    }

    public static ChannelWorkOrderTypeEnum[] specialOfferType() {
        return new ChannelWorkOrderTypeEnum[]{YYHT, GCSAPP, FWSMH, NOTALLOWED};
    }
    public static String getIncludeName(String code) {
        String[] codes = code.split(",", -1);
        List<String> list = new ArrayList<>();
        Arrays.stream(codes).forEach(x -> {
            ChannelWorkOrderTypeEnum of = of(Integer.parseInt(x));
            if (null != of) {
                list.add(of.getName());
            }
        });
        return String.join(",", list);
    }
}
